

import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.server.Unreferenced;
import java.util.ArrayList;


public class SessionClass extends UnicastRemoteObject implements Session, Unreferenced{

	private static final long serialVersionUID = 1L;
	
	private Student object;
	
	protected SessionClass(Student stu) throws RemoteException {
		super();
		this.object = stu;
	}

	@Override
	public void unreferenced() {
		try {
			unexportObject(this, true);
		} catch (NoSuchObjectException e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean logout() throws RemoteException {
		return false;
	}

	@Override
	public String getMSTS() throws RemoteException {
		return object.getMSTS();
	}

	@Override
	public String getStudentName() throws RemoteException {
		return object.getName();
	}

	@Override
	public String getDateOfBirth() throws RemoteException {
		return object.getDateOfBirth();
	}

	@Override
	public String getCourseTitle() throws RemoteException {
		return object.getCurrentCourse().getTitle();
	}

	@Override
	public String getExamTitle() throws RemoteException {
		if(object.getExam() == null) return null;
		return object.getExam().getTitle();
	}

	@Override
	public ArrayList<Question> getQuestions() throws RemoteException {
		if(object.getExam() == null) return null;
		return object.getExam().getQuestion();
	}

	@Override
	public boolean startExam() throws RemoteException {
		if(object.getExam() == null) return false;
		return object.getExam().doExam();
	}

	@Override
	public long getRemainTime() throws RemoteException {
		if(object.getExam() == null) return -1;
		return object.getExam().getRemainTime();
	}

	@Override
	public boolean answerAQuestion(String quest, String answerID) throws RemoteException {
		if(object.getExam() == null) return false;
		return object.getExam().answerQuestion(quest, answerID);
	}
	
}
